/*
 * Copyright (C) 2021 Baidu, Inc. All Rights Reserved.
 */
package com.chukun.rpc.core;

import java.io.Serializable;

/**
 * <p>rpc响应数据体<p/>
 *
 * @author chukun
 * @version 1.0
 * @since 1.0-SNAPSHOT
 */
public class TinyRpcResponse implements Serializable {

    /**
     * 响应消息
     */
    private String message;

    /**
     * 响应数据
     */
    private Object data;

    /**
     * 响应码
     */
    private int  code;

    public TinyRpcResponse() {

    }

    public TinyRpcResponse(String message, Object data, int code) {
        this.message = message;
        this.data = data;
        this.code = code;
    }

    /**
     * 成功响应
     * @param data
     * @return
     */
    public static TinyRpcResponse success(Object data) {
        TinyRpcResponse response = new TinyRpcResponse();
        response.setCode(TinyRpcResponseEnum.SUCCESS.getCode());
        response.setMessage(TinyRpcResponseEnum.SUCCESS.getMessage());
        response.setData(data);
        return  response;
    }

    /**
     * 失败响应
     * @param data
     * @return
     */
    public static TinyRpcResponse error(Object data) {
        TinyRpcResponse response = new TinyRpcResponse();
        response.setCode(TinyRpcResponseEnum.ERROR.getCode());
        response.setMessage(TinyRpcResponseEnum.ERROR.getMessage());
        response.setData(data);
        return  response;
    }


    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }
}
